package com.example.controller;

import cn.hutool.core.date.StopWatch;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.service.impl.RuleSceneDebugService;
import com.example.service.impl.RuleValidatorServiceImpl;
import com.example.vo.RuleValidatorLogDetailPageReqVO;
import com.example.vo.RuleValidatorLogDetailRespVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;


@Slf4j
@RestController
public class TestController {

    @Resource
    RuleValidatorServiceImpl ruleValidatorServiceImpl;
    @Resource
    RuleSceneDebugService ruleSceneDebugService;

    private IPage<RuleValidatorLogDetailRespVO> getValidatorLogDetailPage() {
        StopWatch stopWatch = StopWatch.create("1");
        stopWatch.start();
        RuleValidatorLogDetailPageReqVO vo = new RuleValidatorLogDetailPageReqVO();
        vo.setLogId("9d232d2f3d3440b98233abde6ac148cf");
        vo.setPageNo(1);
        vo.setPageSize(10);
        IPage<RuleValidatorLogDetailRespVO> validatorLogDetailPage = ruleValidatorServiceImpl.getValidatorLogDetailPage(vo);
        stopWatch.stop();
        System.out.println("getValidatorLogDetailPage:"+stopWatch.prettyPrint(TimeUnit.MILLISECONDS));
        return validatorLogDetailPage;
    }

    @GetMapping("/test")
    public String testRule(){
        return JSONUtil.toJsonPrettyStr(getValidatorLogDetailPage());
    }

    @GetMapping("/get/{id}")
    public String testRuleDebug(@PathVariable("id") Long id){
        return JSONUtil.toJsonPrettyStr(ruleSceneDebugService.getOne(id));
    }

}